<?php 

require $this->website['path']['action'].'/admin/isadmin.php';


$json = array('status'=>'error','msg'=>'error','data'=>'');
$uname = fn_post('uname');
$pwd = fn_post('pwd');
$authority = fn_post('authority');
$authoritylist = fn_post('authoritylist');



if(!$uname){
  $json['msg']= '用户名不能为空';
}elseif(strlen($uname)>20 || strlen($uname)<3){
  $json['msg']= '用户名请输入3~20个字符';
}elseif(!$pwd){
  $json['msg']= '密码不能为空';
}elseif($this->website['class']['db']->table('user_admin')->where('uname=?',$uname)->count()){
  $json['msg']= '用户名已存在';
}else{
  $uid = $this->website['class']['db']
             ->table('user_admin')
             ->field('uname','authoritylist','authority','createtime')
             ->value($uname,$authoritylist,$authority,$_SERVER['REQUEST_TIME'])
             ->insert();
  if($uid){
    $this->website['class']['db']
       ->table('user_admin')
       ->field('pwd')
       ->value(password_hash($uid.$pwd,PASSWORD_DEFAULT))
       ->where('id=?',$uid)
       ->update();
    $json['status'] = 'ok';
    $json['msg'] = '账户生成成功';
    $json['data']= 'ok';
  }else{
    $json['msg'] = '账户生成失败';
  }
}




echo json_encode($json);